local lianyan = fk.CreateSkill {
  name = "th_lianyan",
}

lianyan:addEffect(fk.EventPhaseStart, {
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(lianyan.name) and player.phase == Player.Play
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@@th_lianyan-phase", 1)
  end
})
lianyan:addEffect(fk.CardUsing, {
  is_delay_effect = true,
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    if target == player and player:getMark("@@th_lianyan-phase") ~= 0 then
      return data.card.number > player:getMark("@th_lianyan_number-phase")
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, lianyan.name)
    player.room:setPlayerMark(player, "@th_lianyan_number-phase", data.card.number)
  end,
})
lianyan:addEffect(fk.EventPhaseEnd, {
  is_delay_effect = true,
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(lianyan.name) and player:getMark("@@th_lianyan-phase") ~= 0 and player:getHandcardNum() > player:getMaxCards()
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = player:getHandcardNum() - player:getMaxCards()
    local tos, cards = room:askToChooseCardsAndPlayers(player, {
      min_card_num = num,
      max_card_num = num,
      pattern = ".|.|.|hand",
      min_num = 1,
      max_num = 1,
      targets = room:getOtherPlayers(player, false),
      skill_name = lianyan.name,
      prompt = "#th_lianyan-give:::" .. num,
      cancelable = false,
    })
    room:obtainCard(tos[1], cards, nil, fk.ReasonGive, player, lianyan.name)
  end
})

Fk:loadTranslationTable{
  ["th_lianyan"] = "潋滟",
  [":th_lianyan"] = "出牌阶段开始时，你可以令你本阶段使用牌时，若此牌点数大于你本回合此前使用的任何一张牌，你摸一张牌。若如此做，本阶段结束时，你交给一名其他角色超出手牌上限的牌。",

  ["#th_lianyan-invoke"] = "潋滟：你可以令你本阶段使用牌时，若此牌点数大于你本回合此前使用的任何一张牌，你摸一张牌",
  ["#th_lianyan-give"] = "潋滟：请交给一名其他角色%arg张牌",

  ["@@th_lianyan-phase"] = "潋滟",
  ["@th_lianyan_number-phase"] = "潋滟峰值",
}

return lianyan
